﻿<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>
    </title>
    <link href="../../../lib/ligerUI/skins/Aqua/css/ligerui-all.css" rel="stylesheet" type="text/css" />
    <link href="../../../lib/ligerUI/skins/Gray/css/all.css" rel="stylesheet" type="text/css" />
    <script src="../../../lib/jquery/jquery-1.9.0.min.js" type="text/javascript"></script>
    <script src="../../../lib/ligerUI/js/core/base.js" type="text/javascript"></script>
    <script src="../../../lib/ligerUI/js/plugins/ligerForm.js" type="text/javascript"></script>
    <script src="../../../lib/ligerUI/js/plugins/ligerDateEditor.js" type="text/javascript"></script>
    <script src="../../../lib/ligerUI/js/plugins/ligerComboBox.js" type="text/javascript"></script>
    <script src="../../../lib/ligerUI/js/plugins/ligerCheckBox.js" type="text/javascript"></script>
    <script src="../../../lib/ligerUI/js/plugins/ligerButton.js" type="text/javascript"></script>
    <script src="../../../lib/ligerUI/js/plugins/ligerDialog.js" type="text/javascript"></script>
    <script src="../../../lib/ligerUI/js/plugins/ligerRadio.js" type="text/javascript"></script>
    <script src="../../../lib/ligerUI/js/plugins/ligerSpinner.js" type="text/javascript"></script>
    <script src="../../../lib/ligerUI/js/plugins/ligerTextBox.js" type="text/javascript"></script>
    <script src="../../../lib/ligerUI/js/plugins/ligerTip.js" type="text/javascript"></script>
    <script src="../../../lib/jquery-validation/jquery.validate.min.js" type="text/javascript"></script>
    <script src="../../../lib/jquery-validation/jquery.metadata.js" type="text/javascript"></script>
    <script src="../../../lib/jquery-validation/messages_cn.js" type="text/javascript"></script>

    <script type="text/javascript">
        var groupicon = "../../../lib/ligerUI/skins/icons/communication.gif";

        function submitform() {
            var form = liger.get("form1")
            if (!form.valid()) {
                form.showInvalid();
                return;
            }
        }

        $(function () {
            $.metadata.setType("attr", "validate");
            //创建表单结构
            var mainform = $("form");
            var form = mainform.ligerForm({
                inputWidth: 170, labelWidth: 90, space: 40,
                validate: true,
                fields: [
                { display: "产品名称", name: "ProductName", newline: true, type: "text", validate: { required: true, minlength: 3 }, group: "基础信息", groupicon: groupicon },
                  { display: "公司名称", name: "CompanyName", newline: true, type: "text", validate: { required: true } },
                {
                    display: "供应商", name: "SupplierID", textField : 'SupplierName',

                    newline: false, type: "combobox", validate: { required: true }
                }
                ]
                , buttons: [{ text: "保存", width: 60, click: submitform }]
            });

            form.setData({ SupplierID: 'ID', SupplierName: '供应商Name' });


            var validator = $("form").validate({
                //调试状态，不会提交数据的
                debug: true,
                errorPlacement: function (lable, element) {

                    if (element.hasClass("l-textarea")) {
                        element.addClass("l-textarea-invalid");
                    }
                    else if (element.hasClass("l-text-field")) {
                        element.parent().addClass("l-text-invalid");
                    }
                    $(element).removeAttr("title").ligerHideTip();
                    $(element).attr("title", lable.html()).ligerTip();
                },
                success: function (lable) {
                    var element = $("#" + lable.attr("for"));
                    if (element.hasClass("l-textarea")) {
                        element.removeClass("l-textarea-invalid");
                    }
                    else if (element.hasClass("l-text-field")) {
                        element.parent().removeClass("l-text-invalid");
                    }
                    $(element).removeAttr("title").ligerHideTip();
                },
                submitHandler: function () {
                    alert("Submitted!");
                }
            });
        });
    </script>

</head>
<body style="padding:10px">
    <form id="form1"></form>


</body>


</html>